<?php
    // +----------------------------------------------------------------------
    // | 图片文件管理
    // +----------------------------------------------------------------------
    // | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
    // +----------------------------------------------------------------------
    // | Author: 微尘 <yicmf@qq.com>
    // +----------------------------------------------------------------------
    namespace app\controller\file;

    use think\facade\Config;
    use think\facade\Url;
    use app\event\ucenter\User as UserEvent;
    use app\event\file\Image as ImageEvent;

    class Image extends Common
    {


        public function index()
        {
        }

        public function getUrl()
        {
            $url = $this->model->getUrl($this->request->get('id', 0));
            if ($url !== false) {
                $data['url'] = $url;
                $data['code'] = 0;
            } else {
                $data['error'] = $this->model->getError();
                $data['code'] = 20001;
            }
            return json($data);
        }

        /* 图片上传 */
        public function upload()
        {
            if ($this->request->isPost()) {
                $image = new ImageEvent();
                $data = $image->upload($this->request->post(), $this->request->file('file'), $this->user);
            } else {
                $data['code'] = 910002;
                $data['message'] = '请求错误';
            }
            return json($data);
        }
        /* 图片删除 */
        public function delete()
        {
            if ($this->request->isPost()) {
                $image = new ImageEvent();
                $data = $image->delete($this->request->post(), $this->user);
            } else {
                $data['code'] = 910002;
                $data['message'] = '请求错误';
            }
            return json($data);
        }
    }
